package Lee_code;

import java.util.Arrays;

/**
 * @author blh
 * @date 2024年07月12日 10:31
 */
public class Lee_16_712 {
    int res = 9999999;
    int tar;
    int sum;

    public int threeSumClosest(int[] nums, int target) {
        tar = target;
        Arrays.sort(nums);
        int[] seen = new int[nums.length];
        backTrace(0, 0, 0, nums);
        return sum;
    }

    private void backTrace(int curSum, int curNum, int index, int[] nums) {
        if (res == 0) {
            return;
        }
        if (curNum == 3) {
            if (Math.abs(Math.abs(curSum) - Math.abs(tar)) >= res) {
                sum = curSum;
            }
            return ;
        }
        for (int i = index; i < nums.length; i++) {
            backTrace(curSum + nums[i], curNum + 1, i + 1, nums);
        }
    }
}
